﻿Imports System.Windows.Forms
Imports DNP.GestionComercial.BE
Imports DNP.GestionComercial.BL
Imports DNP.GestionComercial.Util
Imports DNP.GestionComercial.FormBase

Public Class frmBuscarRepresentante
    Inherits DNP.GestionComercial.FormBase.frmBusqueda

#Region "Declaracion de variables"

    Dim oMsg As New sisMensaje
    Dim _codigo As String = ""
    Dim _descripcion As String = ""
    Dim _frm As New Windows.Forms.Form

#End Region

    Public Sub New(ByRef codigo As String, ByRef descripcion As String, ByRef frm As Windows.Forms.Form)

        _codigo = codigo
        _descripcion = descripcion
        _frm = frm
        InitializeComponent()

    End Sub

    Public Sub New(ByVal frm As Windows.Forms.Form)

        InitializeComponent()

    End Sub

    Private Sub frmBuscarRepresentante_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        CargarFormulario()
        FormatGrid()
    End Sub

#Region "Funciones"

    Private Sub FormatGrid()

        grdLista.AutoGenerateColumns = False
        grdLista.Columns.Clear()
        grdLista.Columns.Add("NREP_CODIGO", "Codigo")
        grdLista.Columns.Add("CPER_DOCUMENTO", "DNI")
        grdLista.Columns.Add("NOMBRECOMPLETO", "Representante")

        grdLista.Columns(0).DataPropertyName = "NREP_CODIGO"
        grdLista.Columns(1).DataPropertyName = "CPER_DOCUMENTO"
        grdLista.Columns(2).DataPropertyName = "NOMBRECOMPLETO"

        grdLista.Columns(0).Width = 60
        grdLista.Columns(1).Width = 100
        grdLista.Columns(2).Width = 365

        grdLista.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        grdLista.Columns(0).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

        grdLista.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        grdLista.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

        grdLista.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
        grdLista.Columns(2).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

    End Sub

    Private Sub CargarFormulario()

        lblTitulo.Text = "Búsqueda de Representantes"
        Listar()

    End Sub

    Private Sub Listar()

        Dim oRespuesta As New RespuestaBE
        Dim obj As New RepresentanteBE

        obj.CPER_DOCUMENTO = txtEntidad.Text
        obj.NOMBRECOMPLETO = txtDescripcion.Text

        oRespuesta = New RepresentanteBL().ListarTodo(obj)

        If oRespuesta.Respuesta Then
            FormatGrid()
            grdLista.DataSource = oRespuesta.ValorRertono

        Else
            oMsg.showMsgWarning(oRespuesta.Mensaje)
            MsgBox(oRespuesta.Mensaje)
        End If

    End Sub

#End Region

#Region "Eventos de Controles"

    Public Overrides Sub btnAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        If (vRespuesta.PARAMETRO01 Is Nothing) Then
            MsgBox("Seleccione un registro")
        Else
            DialogResult = Windows.Forms.DialogResult.OK
            Me.Hide()
        End If

    End Sub

    Public Overrides Sub grdLista_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

        Dim intfila As Integer
        intfila = grdLista.CurrentRow.Index

        If intfila <> -1 Then

            If grdLista.Rows(intfila).Selected Then

                vRespuesta.PARAMETRO01 = grdLista.Rows(intfila).Cells(1).Value.ToString().Trim() ' DNI
                vRespuesta.PARAMETRO02 = grdLista.Rows(intfila).Cells(2).Value.ToString().Trim() ' Nombre Completo

            End If

        End If

    End Sub


#End Region




End Class